/**
 * 
 */
package design_pattern.decorator.order;

import java.text.NumberFormat;
import java.util.Date;
import java.util.Vector;

/**
 * @author linzq
 * 
 */
public abstract class Order {

  protected OrderLine lnkOrderLine;

  protected String customerName;

  protected Date saleDate;

  protected Vector<OrderLine> items = new Vector<>();

  public void print() {
    for (int i = 0; i < items.size(); i++) {
      OrderLine item = items.get(i);
      item.print();
    }
  }

  public void addItem(OrderLine orderLine) {
    items.add(orderLine);
  }

  public void removeItem(OrderLine orderLine) {
    items.remove(orderLine);
  }

  public double getGrandTotal() {
    double total = 0.0d;
    for (int i = 0; i < items.size(); i++) {
      OrderLine item = items.get(i);
      total += item.getSubTotal();
    }
    return total;
  }

  public String formatCurrency(double total) {
    return NumberFormat.getCurrencyInstance().format(total);
  }

  public OrderLine getLnkOrderLine() {
    return lnkOrderLine;
  }

  public void setLnkOrderLine(OrderLine lnkOrderLine) {
    this.lnkOrderLine = lnkOrderLine;
  }

  public String getCustomerName() {
    return customerName;
  }

  public void setCustomerName(String customerName) {
    this.customerName = customerName;
  }

  public Date getSaleDate() {
    return saleDate;
  }

  public void setSaleDate(Date saleDate) {
    this.saleDate = saleDate;
  }

}
